
/**
 * Author : YeQing
 *
 * @Description This is all page common js.
 */

/**
 * Js Object
 */
var idealBase = idealBase || {

	/**
	 * Custom Ajax function.
	 * @param url
	 * @param param
	 * @param type
	 * @param dataType
	 * @param async
	 * @param callBackFunction
	 */
	doAjaxJson : function(url, param, type, async, callBackFunction) {

		$.ajax({

			// the URL for the request
			url : url,

			// the data to send (will be converted to a query string)
			data : param,

			// aysnc true or false
			async: async,

			// whether this is a POST or GET request
		    type: type,

		    //server return data type
		    dataType: 'json',

		    // code to run if the request succeeds;
		    // the response is passed to the function
		    success: function(xhr, status) {
		    	if(xhr.success != true || status != 'success') {
		    		alert('Ajax Success function : Ajax json detail is undefined.');
		    		return;
		    	}
		    	callBackFunction(xhr);
		    },

		    // code to run if the request fails; the raw request and
		    // status codes are passed to the function
		    error: function(xhr, status) {
		    	alert('Ajax Error function.');
		    }

		});

	},

	/**
	 * Custom Ajax html function.
	 * @param url
	 * @param param
	 * @param type
	 * @param dataType
	 * @param async
	 * @param callBackFunction
	 */
	doAjaxHtml : function(url, param, type, async, callBackFunction) {

		$.ajax({

			// the URL for the request
			url : url,

			// the data to send (will be converted to a query string)
			data : param,

			// aysnc true or false
			async: async,

			// whether this is a POST or GET request
		    type: type,

		    //server return data type
		    dataType: 'html',

		    // code to run if the request succeeds;
		    // the response is passed to the function
		    success: function(xhr, status) {
		    	if(status != 'success') {
		    		alert('Ajax Success function : Ajax json detail is undefined.');
		    		return;
		    	}
		    	callBackFunction(xhr);
		    },

		    // code to run if the request fails; the raw request and
		    // status codes are passed to the function
		    error: function(xhr, status) {
		    	alert('Ajax Error function.');
		    }

		});

	}

};